package com.controller;


import com.controller.abstractcontroller.AbstractController;
import com.flatgen.LoginRequest;
import com.vo.PlayerInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;


@Service
public class LoginController extends AbstractController {


    private Logger logger = LoggerFactory.getLogger(LoginController.class);

    /**
     * spring 容器初始化 加载并初始化相应控制器处理句柄
     * 非spring环境下 可以采用静态的初始化方案
     */
    @Override
    public void PostConstruct() {
        game_controllers[LoginRequest.msgID()] = this;
    }


    /**
     * 基于flatBuffers 结构数据传输
     *
     * @param data   cast subclass of table .         msgID + 游戏数据
     * @param player game session
     * @throws Exception
     */
    @Override
    public void DispatchFlatBuffer(byte[] data, PlayerInstance player) throws Exception {
        LoginRequest loginRequest = LoginRequest.getRootAsLoginRequest(wrap(data));
        logger.info(loginRequest.username());
    }

}